<h2>Invoices</h2>

<div class="block tabs spaces">
	
	<div class="hd">
			<ul>
				<li><a href="<?=site_url('reporting/');?>">Studio Status</a></li>
				<li><a href="<?=site_url('reporting/projection');?>">Projection</a></li>
				<li><a href="<?=site_url('reporting/invoicing');?>">Invoicing</a></li>
			</ul>
		<div class="clear"></div>		
	</div>
	
	<div class="bd">

	
	<p>
		<?php if ($type == 'default'):?>Unprocessed Invoices<?php else:?><a href="<?=site_url('reporting/invoicing');?>">Unprocessed Invoices</a><?php endif;?>
			
		<?php if ($type == 'unpaid'):?>Unpaid Invoices<?php else:?><a href="<?=site_url('reporting/invoicing/unpaid');?>">Unpaid Invoices</a><?php endif;?>
			
		<?php if ($type == 'paid'):?>Paid Invoices<?php else:?><a href="<?=site_url('reporting/invoicing/paid');?>">Paid Invoices</a><?php endif;?>
	</p>

	<img src="<?=$charturl;?>" />
	
	<?php if ($invoices):?>
	<table class="projects invoices">
		<thead>
		<tr>
			<th class="invoice">Invoice</th>
			<th class="project">Project</th>
			<th class="client">Client</th>
			<th class="value numberfield">Value (&pound;)</th>
			<th class="due">Due</th>
			<?php if ($type == 'default'):?>
				<th class="created">Created</th>
			<?php elseif ($type == 'unpaid'):?>
				<th class="processed">Processed</th>
			<?php elseif ($type == 'paid'):?>
				<th class="paid">Paid</th>
			<?php endif;?>
		</tr>
		</thead>
	<tbody>
	
		<?php $total_sum = 0;?>
		<?php foreach($invoices as $invoice):?>
			<?php $total_sum += $invoice->total_cost;?>
			<tr class="<?php if ( time() >= strtotime('+ 14days', strtotime($invoice->duedate)) ) echo 'veryoverdue'; else if (time() >= strtotime($invoice->duedate)) echo 'overdue';?>">
				<td><a href="<?=site_url('jobs/viewinvoice/'.$invoice->id);?>"><?=$invoice->invoicetitle;?></a></td>
				<td><a href="<?=site_url('jobs/showUpdates/'.$invoice->jobid);?>"><?=$invoice->job_title;?></a></td>
				<td><a href="<?=site_url('companies/view/'.$invoice->companyid);?>"><?=$invoice->company_name;?></a></td>
				<td class="numberfield"><?=number_format($invoice->total_cost, 2);?></td>
				<td><?=date('d/m/Y', strtotime($invoice->duedate));?></td>
				<?php if ($type == 'default'):?>
					<td><?=date('H:i d/m/Y', strtotime($invoice->datecreated));?></td>
				<?php elseif ($type == 'unpaid'):?>
					<td><?=date('H:i d/m/Y', strtotime($invoice->processeddate));?></td>
				<?php elseif ($type == 'paid'):?>
					<td><?=date('H:i d/m/Y', strtotime($invoice->paiddate));?></td>
				<?php endif;?>
			</tr>
		<?php endforeach;?>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="3"></td><td class="numberfield"><?=number_format($total_sum, 2);?></td><td colspan="2"></td>
		</tr>
	</tfoot>
	</table>
	<?php endif;?>
</div></div>

